package leetcode

func numWays(n int, relation [][]int, k int) int {
    queue := [][]int{{0, 0}}
    ans := 0

    for len(queue) > 0 {
        person, step := queue[0][0], queue[0][1]
        queue = queue[1:]

        if step == k {
            if person == n - 1 {
                ans ++
            }
        }

        for _, ways := range relation {
            if ways[0] == person{
                queue = append(queue, []int{ways[1], step + 1})
            }
        }
    }

    return ans
}
